package aibili.ronaldo.handler;


import org.assertj.core.util.Maps;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * Exception handling class
 */
//@ControllerAdvice
//@ResponseBody
public class RestfulApiExceptionHandler {
    @ExceptionHandler(value = MissingServletRequestParameterException.class)
    public Map<String, Object> requestExceptionHandler(HttpServletRequest request, MissingServletRequestParameterException exception) {
        Map<String, Object> error = Maps.newHashMap("status", 500);
        error.put("message", "Parameter" + exception.getParameterName() + "error.");
        return error;
    }

    @ExceptionHandler(value = Exception.class)
    public Map<String, Object> exceptionHandler(HttpServletRequest request, Exception exception) throws Exception {
        Map<String, Object> error = Maps.newHashMap("status", 500);
        error.put("message", "Internal Server Error");
        return error;
    }
}
